package com.zz.mapper;

import com.zz.domain.ZipArchive;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ZipArchiveMapper {

    @Insert("INSERT INTO zip_archives(id, exam_id, file_name, file_path, file_size, status, create_time, update_time) " +
            "VALUES(#{id}, #{examId}, #{fileName}, #{filePath}, #{fileSize}, #{status}, #{createTime}, #{updateTime})")
    void insert(ZipArchive archive);

    @Update("UPDATE zip_archives SET " +
            "exam_id = #{examId}, " +
            "file_name = #{fileName}, " +
            "file_path = #{filePath}, " +
            "file_size = #{fileSize}, " +
            "status = #{status}, " +
            "update_time = #{updateTime} " +
            "WHERE id = #{id}")
    void update(ZipArchive archive);

    @Select("SELECT * FROM zip_archives")
    List<ZipArchive> selectAll();

    @Select("SELECT * FROM zip_archives WHERE exam_id = #{examId}")
    List<ZipArchive> selectByExamId(String examId);

    @Select("SELECT * FROM zip_archives WHERE status = #{status}")
    List<ZipArchive> selectByStatus(String status);

    @Select("SELECT * FROM zip_archives ORDER BY create_time DESC LIMIT #{limit}")
    List<ZipArchive> selectLatest(int limit);
}